package com.lf.web.service.system.role;

import javax.servlet.ServletContext;

import org.apache.struts2.util.ServletContextAware;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionSupport;
import com.lf.web.service.ServiceSupport;

public class RoleController extends ActionSupport implements ServletContextAware {

    private WebApplicationContext wac;
    private ServiceSupport cs;

    private String act = "";

    public void setAct(String act) {
        this.act = act;
    }

    public void setServletContext(ServletContext servletContext) {
        wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    }

    public String execute() {
        String rsstr = "";
        switch (act) {
            case "list":
                cs = (ServiceSupport) wac.getBean("RoleListService");
                break;
            case "add":
                cs = (ServiceSupport) wac.getBean("RoleAddService");
                break;
            case "update":
                cs = (ServiceSupport) wac.getBean("RoleUpdateService");
                break;
            case "remove":
                cs = (ServiceSupport) wac.getBean("RoleRemoveService");
                break;
            case "detail":
                cs = (ServiceSupport) wac.getBean("RoleDetailService");
                break;
            default:
                cs = (ServiceSupport) wac.getBean("RoleService");
        }
        rsstr = cs.execute();
        return rsstr;
    }
}
